#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int n,m,s;
bool t;
string last;
struct toy{
    bool face;
    string name;
};toy p[100001];
void print(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>p[i].face>>p[i].name;
    }
}
void solve(){
    int j=1;
    for(int i=1;i<=m;i++){
        cin>>t>>s;
        if(t) { 
            if(p[j].face) j -= s;
            else j += s;
        }
        else { 
            if(p[j].face) j += s;
            else j -= s;
        }
        j %= n;
        if(j <= 0) j += n;
    }
    cout<<p[j].name;
}
int main(){
    freopen("toya.in","r",stdin);
    freopen("toya.out","w",stdout);
    print();
    solve();
    return 0;
}
